<!DOCTYPE html>
<html lang="en">

<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>SB Admin - Blank Page</title>

    <!-- Custom fonts for this template-->
    <link href="/public/Admin/vendor/fontawesome-free/css/all.min.css" rel="stylesheet" type="text/css">

    <!-- Page level plugin CSS-->
    <link href="/public/Admin/vendor/datatables/dataTables.bootstrap4.css" rel="stylesheet">

    <!-- Custom styles for this template-->
    <link href="/public/Admin/css/sb-admin.css" rel="stylesheet">
    <script type="text/javascript" src="/public/jquery/jquery-3.3.1.min.js"></script>
    <script type="text/javascript" src="/public/layer/layer.js"></script>
    <script type="text/javascript" src="/public/layui/layui.js"></script>
    <link rel="stylesheet" href="/public/layui/css/layui.css">
    <style>
        .container {
            width: 100%;
            height: 100%;
        }

        .div_upload_images {
            width: 210px;
            height: 100%;
            float: left;
        }

        .div_upload_file {
            overflow: hidden;
        }
    </style>
</head>

<body id="page-top">

    <nav class="navbar navbar-expand navbar-dark bg-dark static-top">

        <a class="navbar-brand mr-1" href="index.html">Start Bootstrap</a>

        <button class="btn btn-link btn-sm text-white order-1 order-sm-0" id="sidebarToggle" href="#">
            <i class="fas fa-bars"></i>
        </button>

        <!-- Navbar Search -->
        <form class="d-none d-md-inline-block form-inline ml-auto mr-0 mr-md-3 my-2 my-md-0">
            <div class="input-group">
                <input type="text" class="form-control" placeholder="Search for..." aria-label="Search"
                    aria-describedby="basic-addon2">
                <div class="input-group-append">
                    <button class="btn btn-primary" type="button">
                        <i class="fas fa-search"></i>
                    </button>
                </div>
            </div>
        </form>

        <!-- Navbar -->
        <ul class="navbar-nav ml-auto ml-md-0">
            <li class="nav-item dropdown no-arrow mx-1">
                <a class="nav-link dropdown-toggle" href="#" id="alertsDropdown" role="button" data-toggle="dropdown"
                    aria-haspopup="true" aria-expanded="false">
                    <i class="fas fa-bell fa-fw"></i>
                    <span class="badge badge-danger">9+</span>
                </a>
                <div class="dropdown-menu dropdown-menu-right" aria-labelledby="alertsDropdown">
                    <a class="dropdown-item" href="#">Action</a>
                    <a class="dropdown-item" href="#">Another action</a>
                    <div class="dropdown-divider"></div>
                    <a class="dropdown-item" href="#">Something else here</a>
                </div>
            </li>
            <li class="nav-item dropdown no-arrow mx-1">
                <a class="nav-link dropdown-toggle" href="#" id="messagesDropdown" role="button" data-toggle="dropdown"
                    aria-haspopup="true" aria-expanded="false">
                    <i class="fas fa-envelope fa-fw"></i>
                    <span class="badge badge-danger">7</span>
                </a>
                <div class="dropdown-menu dropdown-menu-right" aria-labelledby="messagesDropdown">
                    <a class="dropdown-item" href="#">Action</a>
                    <a class="dropdown-item" href="#">Another action</a>
                    <div class="dropdown-divider"></div>
                    <a class="dropdown-item" href="#">Something else here</a>
                </div>
            </li>
            <li class="nav-item dropdown no-arrow">
                <a class="nav-link dropdown-toggle" href="#" id="userDropdown" role="button" data-toggle="dropdown"
                    aria-haspopup="true" aria-expanded="false">
                    <i class="fas fa-user-circle fa-fw"></i>
                </a>
                <div class="dropdown-menu dropdown-menu-right" aria-labelledby="userDropdown">
                    <a class="dropdown-item" href="#">Settings</a>
                    <a class="dropdown-item" href="#">Activity Log</a>
                    <div class="dropdown-divider"></div>
                    <a class="dropdown-item" href="#" data-toggle="modal" data-target="#logoutModal">Logout</a>
                </div>
            </li>
        </ul>

    </nav>

    <div id="wrapper">

        <!-- Sidebar -->
        <ul class="sidebar navbar-nav">
            <li class="nav-item">
                <a class="nav-link" href="{:url('admin/home/index')}">
                    <i class="fas fa-fw fa-tachometer-alt"></i>
                    <span>仪表盘</span>
                </a>
            </li>
            <li class="nav-item dropdown show">
                <a class="nav-link dropdown-toggle" href="#" id="pagesDropdown" role="button" data-toggle="dropdown"
                    aria-haspopup="true" aria-expanded="true">
                    <i class="fas fa-fw fa-folder"></i>
                    <span>页面</span>
                </a>
                <div class="dropdown-menu show" aria-labelledby="pagesDropdown ">
                    <h6 class="dropdown-header">常用操作</h6>
                    <a class="dropdown-item" href="{:url('admin/classification/index')}">分类管理</a>
                    <a class="dropdown-item" href="{:url('admin/submitmanagement/index')}">投稿管理</a>
                    <a class="dropdown-item active" href="{:url('admin/troubleshooting/index')}">疑难解答</a>
                    <div class="dropdown-divider"></div>
                    <h6 class="dropdown-header">Other Pages:</h6>
                    <a class="dropdown-item" href="404.html">404 Page</a>
                    <a class="dropdown-item " href="blank.html">Blank Page</a>
                </div>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="charts.html">
                    <i class="fas fa-fw fa-chart-area"></i>
                    <span>Charts</span></a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="tables.html">
                    <i class="fas fa-fw fa-table"></i>
                    <span>Tables</span></a>
            </li>
        </ul>

        <div id="content-wrapper">

            <div class="container-fluid">

                <ol class="breadcrumb">
                    <li class="breadcrumb-item">
                        <a href="{:url('admin/home/index')}">仪表盘</a>
                    </li>
                    <li class="breadcrumb-item">
                        <a href="{:url('admin/troubleshooting/index')}">疑难解答</a>
                    </li>
                    <li class="breadcrumb-item active">
                        编辑文章
                    </li>
                </ol>
                <div>
                    <div class="col-md">
                        <div class="col-form-label">
                            <input style="text-align:center" type="text" id="firstName" class="form-control"
                                placeholder="请输入标题" name="title" required="required" autofocus="autofocus">
                        </div>
                    </div>
                </div>
                <div style="height: 200px;" class="col-md">
                    <div class="div_upload_images">
                        <!-- style="width: 220px; float: left;" -->
                        <img id='the_thumbnail'
                            src="data:image/svg+xml;charset=UTF-8,%3Csvg%20width%3D%22200%22%20height%3D%22200%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20200%20200%22%20preserveAspectRatio%3D%22none%22%3E%3Cdefs%3E%3Cstyle%20type%3D%22text%2Fcss%22%3E%23holder_16a2105d1cd%20text%20%7B%20fill%3Argba(255%2C255%2C255%2C.75)%3Bfont-weight%3Anormal%3Bfont-family%3AHelvetica%2C%20monospace%3Bfont-size%3A10pt%20%7D%20%3C%2Fstyle%3E%3C%2Fdefs%3E%3Cg%20id%3D%22holder_16a2105d1cd%22%3E%3Crect%20width%3D%22200%22%20height%3D%22200%22%20fill%3D%22%23777%22%3E%3C%2Frect%3E%3Cg%3E%3Ctext%20x%3D%2274.4296875%22%20y%3D%22104.65%22%3E200x200%3C%2Ftext%3E%3C%2Fg%3E%3C%2Fg%3E%3C%2Fsvg%3E"
                            style="width: 200px;height: 200px;" class="rounded">
                    </div>
                    <br>
                    <div class="div_upload_file">
                        <!-- style="width: auto; float: left;" -->
                        <div class="input-group mb-3">
                            <div class="input-group-prepend">
                                <span class="input-group-text">上传文件</span>
                            </div>
                            <div class="custom-file">
                                <form id='img_upload' method="post" enctype="multipart/form-data">
                                    <input style="width: 100%;" name="file" type="file" accept=".jpg,.png,.bmp,.gif"
                                        class="custom-file-input" id="inputGroupFile01">
                                    <label class="custom-file-label" id='temp_name'
                                        for="inputGroupFile01">点我上传文件</label>
                                </form>
                            </div>
                        </div>
                        <progress value="0" max="100" style="width: 100%;"></progress>
                        <p style="float: left;" id="progress">0 bytes</p>
                        <p style="float: right;" id="info"></p>
                        <br />
                        <input type="button" value="上传文件" onclick="upload()" />
                        <br /><br />
                        上传进度：
                    </div>
                </div>
                <br>
                <div class="col-md">
                    <textarea id="demo" name="textarea" style="display: none;"></textarea>
                </div>
                <br>
                <div class="col-md">
                    <button type="button" onclick="button('save')" style="width: 50%; float: left;"
                        class="btn btn-primary">发表</button>
                    <button type="button" onclick="button('draft')" style="width: 50%; float: left;"
                        class="btn btn-danger">保存草稿</button>
                </div>
            </div>
        </div>
        <!-- /.container-fluid -->
    </div>
    <!-- /.content-wrapper -->
    </div>
    <!-- /#wrapper -->

    <!-- Scroll to Top Button-->
    <a class="scroll-to-top rounded" href="#page-top">
        <i class="fas fa-angle-up"></i>
    </a>

    <!-- Logout Modal-->
    <div class="modal fade" id="logoutModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
        aria-hidden="true">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="exampleModalLabel">Ready to Leave?</h5>
                    <button class="close" type="button" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">×</span>
                    </button>
                </div>
                <div class="modal-body">Select "Logout" below if you are ready to end your current session.</div>
                <div class="modal-footer">
                    <button class="btn btn-secondary" type="button" data-dismiss="modal">Cancel</button>
                    <a class="btn btn-primary" href="login.html">Logout</a>
                </div>
            </div>
        </div>
    </div>

    <!-- Bootstrap core JavaScript-->
    <script src="/public/Admin/vendor/jquery/jquery.min.js"></script>
    <script src="/public/Admin/vendor/bootstrap/js/bootstrap.bundle.min.js"></script>

    <!-- Core plugin JavaScript-->
    <script src="/public/Admin/vendor/jquery-easing/jquery.easing.min.js"></script>

    <!-- Custom scripts for all pages-->
    <script src="/public/Admin/js/sb-admin.min.js"></script>
    <script>
        var index;
        layui.use('layedit', function () {
            var layedit = layui.layedit;
            layedit.set({
                uploadImage: {
                    url: "{:url('admin/troubleshooting/imgupload')}" //接口url
                    , type: 'POST' //默认post
                }
            });
            index = layedit.build('demo'); //建立编辑器

        });
        function button(name) {
            layedit = layui.layedit;
            switch (name) {
                case 'save':
                    $.ajax({
                        type: "POST",
                        url: "{:url('admin/troubleshooting/newhelpadd_post')}",/* 保存地址 */
                        data: {
                            title: $("[name='title']").val(),/* 标题 */
                            the_thumbnail: $("#temp_name").val(),/* 图片地址 */
                            body: layedit.getContent(index),/* 富文本编辑框内容 */
                        },
                        dataType: "JSON",
                        success: function (response) {
                            if (response.code) {
                                alert('发布成功')
                            } else {
                                alert(response.msg);
                            }
                        }
                    });
                    break;
                case 'draft':
                    $.ajax({
                        type: "POST",
                        url: "{:url('admin/troubleshooting/newhelpadd_draft')}",/* 保存地址 */
                        data: {
                            title: $("[name='title']").val(),/* 标题 */
                            the_thumbnail: $("#temp_name").val(),/* 图片地址 */
                            body: layedit.getContent(index),/* 富文本编辑框内容 */
                        },
                        dataType: "JSON",
                        success: function (response) {
                            if (response.code) {
                                alert('保存草稿成功')
                                window.location.href = '{:url(\'admin/troubleshooting/index\')}';
                            } else {
                                alert(response.msg);
                            }
                        }
                    });
                    break;

                default:
                    break;
            }
        }
        var totalSize = 0;
        //绑定所有type=file的元素的onchange事件的处理函数  
        $(':file').change(function () {
            var file = this.files[0]; //假设file标签没打开multiple属性，那么只取第一个文件就行了  
            name = file.name;
            size = file.size;
            type = file.type;
            url = window.URL.createObjectURL(file); //获取本地文件的url，如果是图片文件，可用于预览图片  
            $('#the_thumbnail').attr('src', url)
            $(this).next().html("文件名：" + name + " 文件类型：" + type + " 文件大小：" + (size / 1024 / 1024).toFixed(2) + 'MB' /* + " url: " + url */);
            totalSize += size;
            $("#info").html("总大小: " + totalSize + "bytes");
        });
        function upload() {
            //创建FormData对象，初始化为form表单中的数据。需要添加其他数据可使用formData.append("property", "value");  
            var formData = new FormData($('#img_upload')[0]);
            if ($("#inputGroupFile01").val()) {


                //ajax异步上传  
                $.ajax({
                    url: "{:url('admin/troubleshooting/imgupload')}",
                    type: "POST",
                    data: formData,
                    xhr: function () { //获取ajaxSettings中的xhr对象，为它的upload属性绑定progress事件的处理函数  
                        myXhr = $.ajaxSettings.xhr();
                        if (myXhr.upload) { //检查upload属性是否存在  
                            //绑定progress事件的回调函数  
                            myXhr.upload.addEventListener('progress', progressHandlingFunction, false);
                        }
                        return myXhr; //xhr对象返回给jQuery使用  
                    },
                    success: function (result) {
                        if (result.code) {
                            $('#temp_name').val(result.data.src);
                            alert('上传成功');
                        } else {
                            alert(result.msg);
                        }
                    },
                    contentType: false, //必须false才会自动加上正确的Content-Type  
                    processData: false  //必须false才会避开jQuery对 formdata 的默认处理  
                });
            } else {
                alert('您没有选择文件')
            }
        }
        //上传进度回调函数：  
        function progressHandlingFunction(e) {
            if (e.lengthComputable) {
                $('progress').attr({ value: e.loaded, max: e.total }); //更新数据到进度条  
                var percent = e.loaded / e.total * 100;
                $('#progress').html(e.loaded + "/" + e.total + " bytes. " + percent.toFixed(2) + "%");
            }
        }
    </script>

</body>

</html>